package com.java.array;

public class ArraySortDemo {
    //冒泡排序
    //n个数字来排队，两两相比小靠前，外层循环n-1，内层循环n-1-i
    public static void bubbleSort(int[] array){
        //外层循环控制比较次数
        for (int i = 0; i < array.length-1; i++) {
            //内层循环控制比较次数
            for (int j = 0; j < array.length-1-i; j++) {
                //比较相邻元素，大的交换到后面
                if (array[j] > array[j+1]){
                    int temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {78,44,23,99,34};
        bubbleSort(arr);
        for (int n : arr){
            System.out.println(n);
        }
    }
}
